<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	 
	  <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
    
     <link rel="stylesheet" type="text/css" media="all" href="bootstrap-daterangepicker-master/daterangepicker.css" />
     
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
      <script type="text/javascript" src="bootstrap-daterangepicker-master/moment.js"></script>
      <script type="text/javascript" src="bootstrap-daterangepicker-master/daterangepicker.js"></script>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
		<title></title>
	</head>
	<body>
		<div class="col-md-4 col-md-offset-2 demo">
            <h4>新的</h4>
            <input type="text" id="config-demo" class="form-control">
          <!--  <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>-->
          </div>
          
<script type="text/javascript">
console.log("time=="+new Date())
Date.prototype.Format = function (fmt) { 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	}
getStartRangeTime = function (str){
//		var nowDateEnd = new Date().Format("yyyy/MM/dd hh:mm:ss");
		var end = str.charAt(str.length-1);
		var start = str.substring(0,str.length-1);
		console.log("start==========="+start)
		var nowDateStart = '';
		var newDate = new Date();
		if(end == "d"){//天计算
			 nowDateStart = new Date(newDate.setDate(newDate.getDate() - start));
		}else if(end == "h"){//小时计算
			 nowDateStart = new Date(newDate.setHours(newDate.getHours() - start));
		}else if(end == "M"){//月
			nowDateStart = new Date(newDate.setMonth(newDate.getMonth() - start));
		}else if (end == "y"){//年
			nowDateStart = new Date(newDate.setMonth(newDate.getMonth() - start*12));
		}else if(end == "m"){//分钟
			nowDateStart = new Date(newDate.setMinutes(newDate.getMinutes() - start));
		}
		return nowDateStart;
	} 
	console.log("======="+getStartRangeTime("10y").Format("yyyy/MM/dd hh:mm:ss"))
function f1(){
		$('#config-demo').daterangepicker({
								"showDropdowns": true,//年月可选择
	                   		 	"timePicker": true,//小时可否选择
	                   		 	"timePicker24Hour": true,//24小时制
	                   		 	"timePickerIncrement": 1,//单位分钟，时间间隔
	                   		 	"timePickerSeconds": true,//秒选择
	                   		 	"linkedCalendars": false,//左右时间框，连动翻页
	                   		 	
								singleDatePicker : true,//范围选择开
//								autoApply
//								showWeekNumbers
//								showISOWeekNumbers
//								alwaysShowCalendars
								/**/
								 "dateLimit": {//最大范围
							        "days": 7
							    },
								format: 'YYYY/MM/DD HH:mm:ss',
								locale: {
						                applyLabel: '确认',
						                cancelLabel: '取消',
						                fromLabel: '始',
						                toLabel: '终',
						                //daysOfWeek: ["日","一", "二", "三", "四", "五", "六"],
						                monthNames: [ "一月", "二月","三月","四月","五月","六月","七月","八月","九月","十月", "十一月", "十二月"]
						            }
							},
							function(start, end, label) {
								//回调函数，当确认后触发的js
								console.log(start.toISOString(), end.toISOString(), label);
							});
}
	$('#config-demo').daterangepicker({
		 "showDropdowns": true,//年月可选择
	 	"timePicker": true,//小时可否选择
	 	"timePicker24Hour": true,//24小时制
	 	"timePickerIncrement": 2,//单位分钟，时间间隔
//	 	"timePickerSeconds": true,//秒选择
	 	"linkedCalendars": false,//左右时间框，连动翻页
	 	
//		singleDatePicker : true,//范围选择开
    "locale": {
        "format": "YYYY/MM/DD HH:mm:ss",
        "separator": " - ",
        "applyLabel": "确认",
        "cancelLabel": "关闭",
        "fromLabel": "From",
        "toLabel": "To",
        "customRangeLabel": "自定义",
        "firstDay": 1,
        daysOfWeek: ["日","一", "二", "三", "四", "五", "六"],
		monthNames: [ "一月", "二月","三月","四月","五月","六月","七月","八月","九月","十月", "十一月", "十二月"],
						            
    },
      "ranges": {
      	 "近1小时": [getStartRangeTime("1h"),new Date()],
        "近3小时": [getStartRangeTime("3h"),new Date()],
        "近一天": [getStartRangeTime("1d"),new Date()],
        "7天": [getStartRangeTime("7d"),new Date()],
        "1月": [getStartRangeTime("1M"),new Date()],
       "一年": [getStartRangeTime("1y"),new Date()]
    },
//  "startDate":  ,   //默认开始时间，默认当天开始
   	"endDate": new Date(),
   "minDate": getStartRangeTime("1y"),
   "maxDate":getStartRangeTime("-1y")
}, function(start, end, label) {
  console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});


	
</script>
          
	</body>
</html>
